<%@page import="com.liferay.portal.kernel.language.LanguageUtil"%>
<%@page import="com.mto.module.karaoke.service.CategoryLocalServiceUtil"%>
<%@page import="com.mto.module.karaoke.model.Category"%>
<%@ include file="/jsps/main.jsp"%>

<%
String orderByCol = ParamUtil.getString(request, "orderByCol", "songName");
String orderByType = ParamUtil.getString(request, "orderByType", "asc").toLowerCase();
String 
	songName = ParamUtil.getString(request, "songName", StringPool.BLANK), 
	songAuthor = ParamUtil.getString(request, "songAuthor", StringPool.BLANK), 
	songSinger = ParamUtil.getString(request, "songSinger", StringPool.BLANK), 
	recordNumber = ParamUtil.getString(request, "recordNumber", StringPool.BLANK);
Integer songCategory = ParamUtil.getInteger(request, "songCategory", 0); 

Song searchSong = new SongImpl();
searchSong.setRecordNumber(-1);
searchSong.setSongAuthor(songAuthor);
searchSong.setSongCategory(songCategory);
searchSong.setSongName(songName);
searchSong.setSongSinger(songSinger);

PortletURL authorSearchUrl = renderResponse.createRenderURL();
authorSearchUrl.setParameter("jspPage", "/jsps/phong-thu/view.jsp");
authorSearchUrl.setParameter("tab", "phong-thu");
authorSearchUrl.setPortletMode(PortletMode.VIEW);

PortletURL nameSearchUrl = renderResponse.createRenderURL();
nameSearchUrl.setParameter("jspPage", "/jsps/phong-thu/view.jsp");
nameSearchUrl.setParameter("tab", "phong-thu");
nameSearchUrl.setPortletMode(PortletMode.VIEW);

PortletURL categorySearchUrl = renderResponse.createRenderURL();
categorySearchUrl.setParameter("jspPage", "/jsps/phong-thu/view.jsp");
categorySearchUrl.setParameter("tab", "phong-thu");
categorySearchUrl.setPortletMode(PortletMode.VIEW);

PortletURL singerSearchUrl = renderResponse.createRenderURL();
singerSearchUrl.setParameter("jspPage", "/jsps/phong-thu/view.jsp");
singerSearchUrl.setParameter("tab", "phong-thu");
singerSearchUrl.setPortletMode(PortletMode.VIEW);
%>

<%
PortletURL renderUrl = renderResponse.createRenderURL();
renderUrl.setParameter("tab", "phong-thu");

PortletURL sortUrl = renderResponse.createRenderURL();
sortUrl.setParameter("tab", "phong-thu");
sortUrl.setParameter("jspPage", "/jsps/phong-thu/view.jsp");
sortUrl.setParameter("orderByType", "asc".equals(orderByType) ? "desc" : "asc");
%>

<div class="karaoke-sort">
	<%
	sortUrl.setParameter("orderByCol", "modifiedDate");
	boolean orderByModifiedDate = "modifiedDate".equals(orderByCol);
	boolean orderByRecordNumber = "recordNumber".equals(orderByCol);
	%>
	<a href="<%=sortUrl.toString()%>">
		<liferay-ui:message key="thoi-gian-cap-nhap" />
	</a>
	<c:if test="<%= orderByModifiedDate %>">
		&nbsp;&nbsp;<img src="<%= imgPath + orderByType + ".png"%>">
	</c:if>
	&nbsp;&nbsp;|&nbsp;&nbsp;
	<%
	sortUrl.setParameter("orderByCol", "recordNumber");
	%>
	<a href="<%=sortUrl.toString()%>">
		<liferay-ui:message key="luot-thu" />
	</a>
	<c:if test="<%= orderByRecordNumber %>">
		&nbsp;&nbsp;<img src="<%= imgPath + orderByType + ".png"%>">
	</c:if>
</div>

<div class="karaoke-paging">
	<%
	nameSearchUrl.setParameter("songName", "");
	%>
	<a href="<%=nameSearchUrl.toString()%>"><liferay-ui:message key="tat-ca" /></a>&nbsp;&nbsp;&nbsp;
<%
for(char x = 'A'; x <= 'Z'; x++) {
	nameSearchUrl.setParameter("songName", String.valueOf(x) +StringPool.PERCENT);
	%>
	<a href="<%= nameSearchUrl.toString()%>"><%= x %></a>
	<c:if test="<%= x != 'Z' %>">&nbsp;&nbsp;|&nbsp;&nbsp;</c:if>
	<%
}
%>
</div>

<div id="karaoke-list">
<liferay-ui:search-container emptyResultsMessage="no-song-found" delta="<%=10 %>" orderByCol="<%=orderByCol %>" orderByType="<%=orderByType %>" iteratorURL="<%=tab1Url%>">
	<liferay-ui:search-container-results>
		<%
		results = SongServiceUtil.search(searchSong, searchContainer.getStart(), searchContainer.getEnd(), orderByCol, orderByType);
		results = ListUtil.copy(results);
		total = SongServiceUtil.searchCount(searchSong);
		
		pageContext.setAttribute("results", results);
		pageContext.setAttribute("total", total);
		%>
	</liferay-ui:search-container-results>
	
	<liferay-ui:search-container-row className="com.mto.module.karaoke.model.Song" modelVar="song" keyProperty="songId">
		<%
		String songId = String.valueOf(song.getSongId());
		renderUrl.setParameter("songId", songId);
		%>
		
		<liferay-ui:search-container-column-text name='songName' orderable="<%=true %>" orderableProperty="songName">
			<%
			renderUrl.setParameter("jspPage", "/jsps/phong-thu/view-detail.jsp");
			%>
			<a href="<%=renderUrl.toString()%>" id="songTooltip" title="<%=song.getSongName() %>"><%=song.getSongName() %></a>
		</liferay-ui:search-container-column-text>
		
		<liferay-ui:search-container-column-text name="songAuthor" orderable="<%=true %>" orderableProperty="songAuthor">
			<%
			authorSearchUrl.setParameter("songAuthor", song.getSongAuthor());
			%>
			<a href="<%=authorSearchUrl.toString()%>"><%=song.getSongAuthor() %></a>
		</liferay-ui:search-container-column-text>
		
		<liferay-ui:search-container-column-text name="songCategory" orderable="<%=true %>" orderableProperty="songCategory">
			<%
			categorySearchUrl.setParameter("songCategory", String.valueOf(song.getSongCategory()));
			Category category = CategoryLocalServiceUtil.getCategory(song.getSongCategory());
			%>
			<a href="<%=categorySearchUrl.toString()%>"><%=category.getName() %></a>
		</liferay-ui:search-container-column-text>
		
		<liferay-ui:search-container-column-text name="songSinger" orderable="<%=true %>" orderableProperty="songSinger">
			<%
			singerSearchUrl.setParameter("songSinger", song.getSongSinger());
			%>
			<a href="<%=singerSearchUrl.toString()%>" title="<%=song.getSongSinger() %>"><%=song.getSongSinger() %></a>
		</liferay-ui:search-container-column-text>
		
		<liferay-ui:search-container-column-text name="recordNumber" orderable="<%=true %>" orderableProperty="recordNumber" align="center">
			<%=song.getRecordNumber() %>
		</liferay-ui:search-container-column-text>
		
		<liferay-ui:search-container-column-text align="center" cssClass="w-75px">
			<%
			renderUrl.setParameter("jspPage", "/jsps/phong-thu/record.jsp");
			renderUrl.setParameter("songId", songId);
			%>
			<a href="<%=renderUrl.toString()%>">
<%-- 				<%= LanguageUtil.get(pageContext, "thoi-gian-cap-nhap")%>||| --%>
				<img src="<%= imgPath + "misc.png"%>" title="<liferay-ui:message key="thoi-gian-cap-nhap"/>">
			</a>
		</liferay-ui:search-container-column-text>
	</liferay-ui:search-container-row>
	<liferay-ui:search-iterator />
</liferay-ui:search-container>
</div>

<div class="karaoke-paging">
	<%
	nameSearchUrl.setParameter("songName", "");
	%>
	<a href="<%=nameSearchUrl.toString()%>"><liferay-ui:message key="tat-ca" /></a>&nbsp;&nbsp;&nbsp;
<%
for(char x = 'A'; x <= 'Z'; x++) {
	nameSearchUrl.setParameter("songName", String.valueOf(x) +StringPool.PERCENT);
	%>
	<a href="<%= nameSearchUrl.toString()%>"><%= x %></a>
	<c:if test="<%= x != 'Z' %>">&nbsp;&nbsp;|&nbsp;&nbsp;</c:if>
	<%
}
%>
</div>